package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BsLotteryHistory;
import com.ruoyi.system.service.IBsLotteryHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抽奖记录Controller
 * 
 * @author ruoyi
 * @date 2022-12-25
 */
@RestController
@RequestMapping("/system/history")
public class BsLotteryHistoryController extends BaseController
{
    @Autowired
    private IBsLotteryHistoryService bsLotteryHistoryService;

    /**
     * 查询抽奖记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsLotteryHistory bsLotteryHistory)
    {
        startPage();
        List<BsLotteryHistory> list = bsLotteryHistoryService.selectBsLotteryHistoryList(bsLotteryHistory);
        return getDataTable(list);
    }

    /**
     * 导出抽奖记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "抽奖记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsLotteryHistory bsLotteryHistory)
    {
        List<BsLotteryHistory> list = bsLotteryHistoryService.selectBsLotteryHistoryList(bsLotteryHistory);
        ExcelUtil<BsLotteryHistory> util = new ExcelUtil<BsLotteryHistory>(BsLotteryHistory.class);
        util.exportExcel(response, list, "抽奖记录数据");
    }

    /**
     * 获取抽奖记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{lotteryId}")
    public AjaxResult getInfo(@PathVariable("lotteryId") Long lotteryId)
    {
        return AjaxResult.success(bsLotteryHistoryService.selectBsLotteryHistoryByLotteryId(lotteryId));
    }

    /**
     * 新增抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "抽奖记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsLotteryHistory bsLotteryHistory)
    {
        return toAjax(bsLotteryHistoryService.insertBsLotteryHistory(bsLotteryHistory));
    }

    /**
     * 修改抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "抽奖记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsLotteryHistory bsLotteryHistory)
    {
        return toAjax(bsLotteryHistoryService.updateBsLotteryHistory(bsLotteryHistory));
    }

    /**
     * 删除抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "抽奖记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lotteryIds}")
    public AjaxResult remove(@PathVariable Long[] lotteryIds)
    {
        return toAjax(bsLotteryHistoryService.deleteBsLotteryHistoryByLotteryIds(lotteryIds));
    }
}
